﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using CamDo.DAO;
using CamDo.DTO;

namespace CamDo
{
    public partial class frmList : DevComponents.DotNetBar.RibbonForm
    {
        private DataTable data;
        private bool edit = false;
        private bool chuocDo = false;

        public bool ChuocDo
        {
            get { return chuocDo; }
            set { chuocDo = value; }
        }
        public bool Edit
        {
            get { return edit; }
            set { edit = value; }
        }
        private bool delete = false;

        public bool Delete
        {
            get { return delete; }
            set { delete = value; }
        }
        public frmList()
        {
            InitializeComponent();
        }
        public void setDataSource(DataTable data)
        {
            this.data = data;
        }
        
       

        private void frmList_Load(object sender, EventArgs e)
        {
            this.listData.DataSource= this.data;
           

        }

        private void listData_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           
            if(this.Edit){
                int rowIndex = e.RowIndex;
                DataGridViewRow row = listData.Rows[rowIndex];
                String maMatHang = listData.Rows[rowIndex].Cells[0].Value.ToString();
                CamDoDAO camdoDAO = new CamDoDAO();
                HangHoa matHang=camdoDAO.getARow(maMatHang);
                frmAdd editForm = new frmAdd();
                editForm.MdiParent = this.MdiParent;
                editForm.Dock = DockStyle.Fill;
                editForm.setTitleLabel("SỬA THÔNG TIN MẶT HÀNG");
                editForm.Edit = true;
                editForm.HangHoa = matHang;
                editForm.loadDataEdit();
                //MessageBox.Show(camdoDAO.Error);
                editForm.Show();
                
            }
            if (this.Delete)
            {
                int rowIndex = e.RowIndex;
                DataGridViewRow row = listData.Rows[rowIndex];
                String maMatHang = listData.Rows[rowIndex].Cells[0].Value.ToString();
                if (MessageBox.Show("Bạn muốn xóa mặt hàng"+maMatHang, "Confirm delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    CamDoDAO camdoDAO = new CamDoDAO();
                    camdoDAO.deleteARow(maMatHang);
                    frmList list = new frmList();
                    list.MdiParent = this.MdiParent;
                    list.Dock = DockStyle.Fill;
                    list.Edit = true;
                    CamDoDAO camdoDao = new CamDoDAO();
                    list.setDataSource(camdoDao.getAllData());
                    // MessageBox.Show(camdoDao.Error);

                    list.Show(); 
                }
            }
            if (this.ChuocDo)
            {
                int rowIndex = e.RowIndex;
                DataGridViewRow row = listData.Rows[rowIndex];
                String maMatHang = listData.Rows[rowIndex].Cells[0].Value.ToString();
                if (MessageBox.Show("Bạn muốn xóa chuộc đồ: " + maMatHang, "Confirm delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    CamDoDAO camdoDAO = new CamDoDAO();
                    //camdoDAO.deleteARow(maMatHang);
                    frmList list = new frmList();
                    list.MdiParent = this.MdiParent;
                    list.Dock = DockStyle.Fill;
                    list.Edit = true;
                    CamDoDAO camdoDao = new CamDoDAO();
                    list.setDataSource(camdoDao.getAllData());
                    // MessageBox.Show(camdoDao.Error);

                    list.Show();
                }
            }
        }
    }
}